function Bits = jpgDCbits(dc,C)
% Bits = jpgDCbits(dc,C)
% Computes the exact number of bits to entropy code
% the DC differential coefficient using the JPEG default
% Huffman tables.
% Input:
% dc = predicted DC differential value
% C = 'Y' for luma or 'C' for chroma
% Output:
% # of bits for the DC differential
%
% CodeLengthY contains the lengths of codes for the
% luma DC differential for size categories fro 0 to 11 inclusive.
% Code length equals the length of the Huffman code for
% the size category plus the binary code for the value.
% CodeLengthC is the corresponding table for the chroma.
CodeLengthY = int16([3 4 5 5 7 8 10 12 14 16 18 20]);%cho thanh phan luma
CodeLengthC = int16([2 3 5 6 7 9 11 13 15 18 19 20]);%cho thanh phan chroma
switch C
case 'Y'
CodeLength = CodeLengthY;
case 'C'
CodeLength = CodeLengthC;
end
if dc == 0
Bits = double(CodeLength(1));
else
Bits = double(CodeLength(round(log2(abs(dc))+0.5)+1));

end
